﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;


namespace GraphDrawing
{
    class savegraphml
    {
        public void savegraph(List<Vertex> wierzcholki, List<Edge> krawedzie, string lokacja)
        {
                        XmlWriterSettings s = new XmlWriterSettings();
            s.Indent = true;
            XmlWriter w = XmlWriter.Create(lokacja, s);
            w.WriteStartElement("graphml", "http://graphml.graphdrawing.org/xmlns");
            w.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
            w.WriteAttributeString("xsi", "schemaLocation", null, "http://graphml.graphdrawing.org/xmlns" + " http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd");
            w.WriteStartElement("graph");
            w.WriteAttributeString("id", "G");
            w.WriteAttributeString("edgedefault", "undirected");
             for (int i = 0; i < wierzcholki.Count; i++)
             {
                 w.WriteStartElement("node");
                 w.WriteAttributeString("id", "n" + i.ToString());
                 w.WriteEndElement();
             }
           
                 for (int j = 0; j < krawedzie.Count; j++)
                 {
                             w.WriteStartElement("edge");
                             w.WriteAttributeString("source", "n" + krawedzie[j].v1.ToString());
                             w.WriteAttributeString("target", "n" + krawedzie[j].v2.ToString());
                             w.WriteEndElement();
                        
                     
                 }
             
             w.WriteEndElement();
             w.Close();

        }


    }
}
